package com.itheima.arraysdemo;

import java.util.Arrays;
import java.util.Comparator;

public class MyArraysDemo1 {
    public static void main(String[] args) {
        //常见的算法API->Arrays,里面基本都是static，用类名直接调用

        int[] arr = {7, 4, 2, 13, 1, 3, 12, 10, 5, 8, 9, 6, 11};

        Integer[] arr1 = {7, 4, 2, 13, 1, 3, 12, 10, 5, 8, 9, 6, 11};

        int[] arr2 ={1,2,3,4,5,6,7,8,9,10};
        //把数组拼接成字符串
        String string = Arrays.toString(arr);
        System.out.println(string);

        //二分查找法查找元素(要求被查找的数组内元素是有序的）
        int i = Arrays.binarySearch(arr2, 1);
        System.out.println(i);

        //拷贝数组
        int[] ints = Arrays.copyOf(arr, 3);
        System.out.println(Arrays.toString(ints));

        //拷贝数组（指定范围）(包左不包右）
        int[] ints1 = Arrays.copyOfRange(arr, 2, 3);
        System.out.println(Arrays.toString(ints1));

        //填充数组
//        Arrays.fill(arr,29);
//        System.out.println(Arrays.toString(arr));

        //按照默认方式进行数组排序
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        //按照指定方式排序
        Arrays.sort(arr1,new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        System.out.println(Arrays.toString(arr1));
    }
}
